package com.g8.pethospitallearnbackend.controller;

import com.g8.pethospitallearnbackend.entity.Paper;
import com.g8.pethospitallearnbackend.entity.PaperExample;
import com.g8.pethospitallearnbackend.entity.Question;
import com.g8.pethospitallearnbackend.service.PaperService;
import jakarta.websocket.server.PathParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/paper")
public class PaperController {
    @Autowired
    PaperService paperService;

    @GetMapping
    public List<Paper> getAllPaper(){
        List<Paper> list = paperService.getAllPaper();
        return list;
    }

    @RequestMapping("/{paperId}")
    public Paper getPaperById(@PathVariable("paperId") String paperId){
        Paper paper = paperService.getPaperById(paperId);
        return paper;
    }

    @RequestMapping("/searchpaper")
    public List<Paper> searchPaper(@RequestParam String searchPaper){
        List<Paper> papers = paperService.searchPaper(searchPaper);
        return papers;
    }

    @PostMapping
    public Paper addPaper(@RequestBody Paper paper){
        return paperService.addPaper(paper);
    }

    @PutMapping
    public Paper changePaper(@RequestBody Paper paper){
        return paperService.changePaper(paper);
    }

    @DeleteMapping("/{paperId}")
    public void deletePaper(@PathVariable("paperId") String paperId){
        paperService.deletePaper(paperId);
    }
}
